﻿@namespace LaserMark.Components.Components
@using LaserMark.SuperDog
@using System.Windows
<Tab IsBorderCard="true" Placement="Placement.Bottom" IsOnlyRenderActiveTab="true" class="tabs1" OnBeforeClickTabItemAsync="OnClickTabItemAsync">
    <TabItem Text="设备参数">
        <Tab IsBorderCard="true" IsCard="true" Placement="Placement.Left" IsOnlyRenderActiveTab="true">
            <TabItem Text="I/O信号点">
                <IOPointStatus></IOPointStatus>
            </TabItem>
            <TabItem Text="回零控制">
                <ZeroControl></ZeroControl>
            </TabItem>
            <TabItem Text="传送参数">
                <Comprehensive></Comprehensive>
            </TabItem>
            <TabItem Text="光电扫描">
                <Photoelectricity></Photoelectricity>
            </TabItem>
            <TabItem Text="连线参数">
                <ConnectLineSettings></ConnectLineSettings>
            </TabItem>
            <TabItem Text="打码参数">
                <MarkArgsSetting></MarkArgsSetting>
            </TabItem>
            <TabItem Text="测高参数">
                <AltimetryParameters></AltimetryParameters>
            </TabItem>
            <TabItem Text="打码模板">
                <CodeTemplate></CodeTemplate>
            </TabItem>
            <TabItem Text="G配置">
                <GcodeReadOrder></GcodeReadOrder>
            </TabItem>
        </Tab>
    </TabItem>

    <TabItem Text="制造商">
        <Tab IsBorderCard="true" IsCard="true" Placement="Placement.Left" IsOnlyRenderActiveTab="true">
            <TabItem Text="设备参数">
                <Machine></Machine>
            </TabItem>
        </Tab>
    </TabItem>
</Tab>

@code
{
    [Inject]
    [NotNull]
    private SwalService? SwalService { get; set; }

    [Inject]
    [NotNull]
    private IDogService? DogService { get; set; }

    [NotNull]
    private string? Pwd { get; set; }

    private async Task<bool> OnClickTabItemAsync(TabItem tab)
    {
        if (tab.Text == "制造商")
        {
            var ret = await SwalService.ShowModal(new SwalOption()
                {
                    Category = SwalCategory.Warning,
                    BodyTemplate = BootstrapDynamicComponent.CreateComponent<BootstrapPassword>(new Dictionary<string, object?>
                    {
                        [nameof(BootstrapPassword.DisplayText)] = "请输入制造商密码",
                        [nameof(BootstrapPassword.ShowLabel)] = true,
                        [nameof(BootstrapPassword.Value)] = Pwd,
                        [nameof(BootstrapPassword.ValueChanged)] = EventCallback.Factory.Create<string>(this, v =>
                        {
                            Pwd = v;
                        })
                    }).Render()
                });

            if (ret)
            {
                var sn = await DogService.GetSn();
                if (sn.Equals(Pwd))
                {
                    Pwd = "";
                    return true;
                }
                else
                {
                    Pwd = "";
                    MessageBox.Show("服务商密码输入错误");
                    return false;
                }
            }
            else
            {
                Pwd = "";
                return false;
            }
        }
        else
        {
            return true;
        }
    }
}
